package com.zd.composedemo.ui.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.graphics.toColorInt
import com.zd.composedemo.R

/**
 * 顶部公共布局
 */
@Composable
fun TopLayout(title: String?, modifier: Modifier = Modifier) {
    Row(
        horizontalArrangement = Arrangement.SpaceEvenly,
        modifier = modifier
            .fillMaxWidth()
            .padding(10.dp, 3.dp)
    ) {
        Image(
            painter = painterResource(R.drawable.baseline_arrow_back_24),
            contentDescription = "topBackIcon",
            modifier = Modifier
                .size(45.dp)
                .padding(0.dp, 10.dp)
                .align(Alignment.CenterVertically),
            colorFilter = ColorFilter.tint(Color.Red)
        )

        title?.let {
            Text(
                it,
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(0.dp, 0.dp, 45.dp, 0.dp)
                    .align(Alignment.CenterVertically),
//                    .border(
//                        1.dp, color = Color.Red, RoundedCornerShape(5.dp)
//                    )
//                    .background(
//                        MaterialTheme.colorScheme.primaryContainer,
//                        RoundedCornerShape(10.dp)
//                    )
                fontSize = 16.sp,
                fontWeight = FontWeight.W500,
                textAlign = TextAlign.Center,
                color = Color("#FF4400".toColorInt()),
                style = MaterialTheme.typography.titleSmall,
            )
        }
    }
}

@Preview(showBackground = true, name = "顶部布局")
@Composable
fun prevTopLayout() {
    TopLayout("你想要的小红书")
}